package cn.school.controller.prevention;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.prevention.entity.Info;
import cn.school.prevention.service.InfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "t_prevention_info => 防控信息表")
@RequestMapping("/prevention")
public class InfoController {

    @Autowired
    private InfoService infoService;


    @ApiOperation("addInfo => 新增防控信息表")
    @PostMapping("/addInfo")
    public CommonResult<Integer> addInfo(@RequestBody Info info) throws SchedulerException {
        int insert = infoService.insert(info,false);
        if (insert > 0) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("updateInfo => 修改防控信息表")
    @PostMapping("/updateInfo")
    public CommonResult<Integer> updateInfo(@RequestBody Info info) {
        int num = infoService.update(info);
        if (num > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("infoPageList => 分页查询防控信息表")
    @PostMapping(value = "/infoPageList")
    public CommonResult<CommonPage<Info>> infoPageList(@RequestBody Info info) {
        IPage<Info> infoIPage = infoService.infoPageList(info);
        return CommonResult.success(CommonPage.restPage(infoIPage));
    }

    @ApiOperation("infoDelete => 删除防控信息表")
    @PostMapping(value = "/infoDelete")
    public CommonResult<Integer> infoDelete(@RequestBody Info info) {
        int i = infoService.deleteInfo(info);
        if (i > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @PostMapping(value = "/deleteByPrimaryKey")
    public CommonResult<Integer> deleteByPrimaryKey(@RequestBody Info info) {
        int i = infoService.delete(info);
        if (i > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
